package com.csk.zsk.compents.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csk.zsk.commons.orm.PropertyFilter.MatchType;
import com.csk.zsk.compents.dao.BookChaptersDao;
import com.csk.zsk.compents.dao.BookDao;
import com.csk.zsk.compents.entity.Book;
import com.csk.zsk.compents.entity.BookChapters;
import com.csk.zsk.compents.service.BookService;

@Service
@Transactional
public class BookServiceImpl implements BookService {

	@Autowired
	private BookDao bookDao;
	@Autowired
	private BookChaptersDao bookChaptersDao;
	
	@Override
	@Transactional(readOnly = true)
	public Book searchBookById(String id) {
		return bookDao.getIdByGetMethod(id);
		
	}



	@Override
	@Transactional(readOnly = true)
	public List<Book> searchTop10ByOrder(String startIndex) {
		return bookDao.searchTop10ByOrder(startIndex);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Book> searchTop10ByRec(String startIndex) {
		return bookDao.searchTop10ByRec(startIndex);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Book> searchTop10ByRandom() {
		return bookDao.searchTop10ByRandom();
	}

	@Override
	@Transactional(readOnly = true)
	public BookChapters searchBookChaptersById(String id) {
		return bookChaptersDao.getIdByGetMethod(id);
	}



	@Override
	public List<Book> searchBookByAuthor(String author) {
		return bookDao.findBy("author", author);
	}



	@Override
	public List<Book> searchBookByLikeName(String likename) {
		return bookDao.findBy("name", likename, MatchType.LIKE);	
	}



	@Override
	public List<BookChapters> searchBookChaptersByBookId(String id) {
		return bookChaptersDao.searchBookChaptersByBookId(id);
	}

}
